package top.revery.api.config;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by  revery.top jun
 * Date  2019-12-02 13:50
 *
 * <h1> --- 统一接口请求返回标准 ---- </h1>
 */
@Data
@NoArgsConstructor
public class HttpResponResult {
    private ResultType resultType = ResultType.SUCCESS;

    private String errorMsg;

    private Map<String,Object> data;

    public Exception exception;

    /*
    * 构造一
    * */
    public HttpResponResult(ResultType resultType) {
        this.resultType = resultType;
    }

    /*
     * 构造二
     * */
    public HttpResponResult(ResultType resultType, String errorMsg) {
        this.resultType = resultType;
        this.errorMsg = errorMsg;
    }

    /*
    * 向DATA插入数据
    * */
    public void put(String key, Object value){
        if(data==null){
            data = new HashMap<String, Object>();
        }

        data.put(key,value);
    }

    /*
     * 移除DATA数据
     * */
    public void remove(String key){
        if(data==null){
            data = new HashMap<String, Object>();
            return;
        }
        data.remove(key);
    }
}
